<template>
	<view class="columnbox wdh-100 content">
		<template v-if="stationinfo!=''">
			<swiper class="swiper-box">
				<swiper-item v-for="(item,index) in stationinfo.listUrl" :key='index'>
					<image mode="aspectFill" :src="item.url">
					</image>
				</swiper-item>
			</swiper>
			<view class="columnbox wdh-100 info-box">
				<view class=" rowbox wdh-100 spb">
					<view class="rowbox">
						<view class="store-name">{{stationinfo.name}}</view>
						<view class="rowbox s-qj" v-if="stationinfo.stationType==0">旗舰站</view>
						<view class="rowbox s-jm" v-else-if="stationinfo.stationType==1">标准站</view>
						<view class="rowbox s-zz" v-else-if="stationinfo.stationType==2">自助站</view>
						<view class="rowbox s-zd" v-else-if="stationinfo.stationType==3">自动站</view>
					</view>
					<!-- <view class="rowbox jifen-box">可获得1积分</view> -->
				</view>
				<view class="rowbox wdh-100 spb" style="margin: 20rpx 0;">
					<view class="rowbox">
						<view class="s-address">{{stationinfo.address}}</view>
						<!-- 	<view class="s-address" style="margin-left: 20rpx;">
							<image src="/static/img/weizhi.png" mode="widthFix" style="width: 20rpx;height: 20rpx;">
							</image>{{stationinfo.distance>1000?stationinfo.distance/1000+'KM':(stationinfo.distance+'M')}}
						</view> -->
					</view>
					<image @click="showMap" src="/static/img/location.svg" mode="widthFix" class="location-icon">
					</image>
				</view>

			</view>
			<view class="line-box"></view>
			<view class="rowbox jus type-title">选择洗车类型</view>
			<!-- 自动洗车 -->
			<view v-if="stationinfo.zdDoors.length>0" class="columnbox one-type" @click="curtype=1,doorId=''"
				:class="{'sel-type':curtype==1}">
				<view class="rowbox wdh-100 spb als top-box">
					<view class="columnbox">
						<image src="/static/img/zdxc.png" mode="widthFix" class="type-img"></image>
						<view class="type-name">自动洗车</view>
					</view>
					<view class="columnbox type-desc als">
						<view><text class="def-col">自动洗车说明：</text><text
								style="color: #000;">{{feeSettingszd.directions}}</text> </view>
						<view style="margin-top: 20rpx;"><text class="def-col">支付费用：</text>
							全自动洗车{{feeSettingszd.basePrice}}元/次或
							消耗洗车券一张 </view>
					</view>
				</view>
				<view class="wdh-100 rowbox price-box">
					费用{{feeSettingszd.baseDuration}}分钟{{feeSettingszd.basePrice}}元，每超1分钟增加费用{{feeSettingszd.overtimeHarges}}元
				</view>
				<view class="wdh-100 room-list" v-if="curtype==1">
					<view @click.stop="doorId=item.doorId" class="rowbox one-room"
						:class="{'sel-type':item.doorId==doorId}" v-for="(item,index) in stationinfo.zdDoors"
						:key='index'>
						<image src="/static/img/xcj.png" mode="widthFix"></image>
						<view>{{item.doorName}}</view>
						<view v-if="item.opesType==0" class="status-box" style="color: #36BA4B;">闲</view>
						<view v-else-if="item.opesType==2" class="status-box"
							style="color: #101010;background: #b6b6b6;">修
						</view>
						<view v-else-if="item.opesType==1" class="status-box" style="color: #bc2b25;">使用中</view>
					</view>
				</view>
			</view>
			<!-- 自助洗车 -->
			<view v-if="stationinfo.zzDoors.length>0" class="columnbox one-type" @click="curtype=2,doorId=''"
				:class="{'sel-type':curtype==2}">
				<view class="rowbox wdh-100 spb als top-box">
					<view class="columnbox">
						<image src="/static/img/zzcx.png" mode="widthFix" class="type-img"></image>
						<view class="type-name">自助洗车</view>
					</view>
					<view class="columnbox type-desc als">
						<view><text class="def-col">自助洗车说明：</text><text
								style="color: #000;">{{feeSettingszz.directions}}</text> </view>
						<view style="margin-top: 20rpx;"><text class="def-col">支付费用：</text>
							全自助洗车{{feeSettingszz.basePrice}}元/次或
							消耗洗车券一张 </view>
					</view>
				</view>
				<view class="wdh-100 rowbox price-box">
					费用{{feeSettingszz.baseDuration}}分钟{{feeSettingszz.basePrice}}元，每超1分钟增加费用{{feeSettingszz.overtimeHarges}}元
				</view>
				<view class="wdh-100 room-list" v-if="curtype==2">
					<view @click.stop="doorId=item.doorId" class="rowbox one-room"
						:class="{'sel-type':item.doorId==doorId}" v-for="(item,index) in stationinfo.zzDoors"
						:key='index'>
						<image src="/static/img/xcj.png" mode="widthFix"></image>
						<view>{{item.doorName}}</view>
						<view v-if="item.opesType==0" class="status-box" style="color: #36BA4B;">闲</view>
						<view v-else-if="item.opesType==2" class="status-box"
							style="color: #101010;background: #b6b6b6;">修
						</view>
						<view v-else-if="item.opesType==1" class="status-box" style="color: #bc2b25;">使用中</view>
					</view>
				</view>
			</view>
			<!-- 人工洗车 -->
			<view v-if="stationinfo.rgDoors.length>0" class="columnbox one-type" @click="curtype=3,doorId=''"
				:class="{'sel-type':curtype==3}">
				<view class="rowbox wdh-100 spb als top-box">
					<view class="columnbox">
						<image src="/static/img/rgyy.png" mode="widthFix" class="type-img"></image>
						<view class="type-name">人工洗车</view>
					</view>
					<view class="columnbox type-desc als">
						<view><text class="def-col">人工洗车说明：</text> 将车辆驶入指定地点
							内 <text style="color: #000;">后由店内工作人员完成洗车</text> </view>
						<view style="margin-top: 20rpx;"><text class="def-col">支付费用：</text> 全自动洗车30.00元/次或
							消耗洗车券一张 </view>
					</view>
				</view>
				<view class="wdh-100 rowbox price-box">费用40.00元每次</view>
			</view>
		</template>
		<view class="line-box"></view>
		<view class="columnbox wdh-100 info-box" style="margin: 0;border-radius: 0;">
			<view class="rowbox wdh-100 spb store-info">
				<view class="rowbox">
					<image src="/static/img/yysj.png" mode="widthFix" class="store-icon"></image>
					营业时间
				</view>
				<view>{{getBusinessHours(stationinfo.businessHours)}}</view>
			</view>
			<view class="rowbox wdh-100 spb store-info" @click="callPhone(stationinfo.phone)">
				<view class="rowbox">
					<image src="/static/img/zzdh.png" mode="widthFix" class="store-icon"></image>
					站长电话
				</view>
				<view class="def-col">{{stationinfo.phone}}</view>
			</view>
			<view class="rowbox wdh-100 spb store-info" @click="callPhone(stationinfo.hotline)">
				<view class="rowbox">
					<image src="/static/img/zzdh.png" mode="widthFix" class="store-icon"></image>
					客服电话
				</view>
				<view class="def-col">{{stationinfo.hotline}}</view>
			</view>
			<view class="rowbox wdh-100 spb store-info" style="position: relative;"
				@click="callPhone(stationinfo.hotline)">
				<button open-type="contact"
					style="position: absolute;width: 100%;height: 100%;z-index: 2;opacity: 0;"></button>
				<view class="rowbox">
					<image src="/static/img/kefu.png" mode="widthFix" class="store-icon"></image>
					联系在线客服
				</view>
				<u-icon name="arrow-right" size="24rpx"></u-icon>
			</view>
		</view>
		<view class="wdh-100" style="height: 200rpx;"></view>
		<view class="rowbox bottom-box">
			<view class="rowbox account-box" @click="toRecharge">
				¥ {{isLogin?(walletinfo.cash||0):0}} 充值余额
			</view>
			<!-- <view class="rowbox pay-btn">请选择洗车类型</view> -->
			<view @click="confirmOrder" class="rowbox pay-btn confirm-btn">开始洗车</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				doorId: '',
				stationinfo: '',
				walletinfo: '',
				submitflag: false,
				couponsId: '',
				feeSettingszd: '',
				feeSettingszz: '',
				feeSettingsrg: '',
				door: '',
				curtype: 0
			};
		},
		computed: {
			// 通过计算属性将 state 中的 count 映射到组件
			isLogin() {
				return this.$store.state.isLogin;
			},
			userInfo() {
				return this.$store.state.user;
			},
		},
		async onLoad(options) {
			await this.$onLaunched;
				console.log('===二维码获取内容====', options)
			this.doorId = options.door_id
			this.getDoorInfo()
		},
		onShow() {
			this.$nextTick(() => {
				if (this.isLogin) {
					this.getWallet()
				}
			})
		},
		methods: {
			getBusinessHours(v) {
				switch (v) {
					case 0:
						return '0-24h'
						break;
					default:
						return '8-18h'
						break;
				}
			},
			getDoorInfo() {
				this.$req.get(`/xcx/stationDoor/qr/${this.doorId}`).then(res => {
					if (res.data.code == 200) {
						if (res.data.data.door.opesType == 1) {
							uni.showModal({
								title: '工位正在使用中',
								content: '请选择其他工位',
								success: (res) => {

								}
							})
						}
						if (res.data.data.door.opesType == 2) {
							uni.showModal({
								title: '工位正在维修中',
								content: '请选择其他工位',
								success: (res) => {

								}
							})
						}
						this.curtype = res.data.data.door.doorType + 1
						this.door = this.stationinfo.door
						this.stationDetail(res.data.data.stationId)
					} else {
						uni.showModal({
							title: '开门失败',
							content: res.data.msg,
							complete() {
								uni.switchTab({
									url: '/pages/index/index'
								})
							}
						})
					}
				})
			},
			stationDetail(stationId) {
				this.$req.get(`/xcx/station/${stationId}`).then(res => {
					this.stationinfo = res.data.data
					res.data.data.listUrl = res.data.data.listUrl.indexOf('url') ? JSON.parse(res.data.data
						.listUrl) : []
					res.data.data.feeSettings.forEach(resp => {
						if (resp.washType == 0) {
							this.feeSettingszd = resp
						}
						if (resp.washType == 1) {
							this.feeSettingszz = resp
						} else {
							this.feeSettingsrg = resp
						}
					})
					this.stationinfo.zdDoors = res.data.data.zdDoors
					this.stationinfo.zzDoors = res.data.data.zzDoors
					// this.stationinfo.rgDoors = res.data.data.rgDoors
				})
			},
			getWallet() {
				this.$req.get('/xcx/userWallet').then(res => {
					if (res.data.data) {
						this.walletinfo = res.data.data
					}
				})
			},
			toRecharge() {
				if (!this.isLogin) {
					this.$noLog()
					return false
				}
				uni.navigateTo({
					url: '/pages/coupon/buyCoupon'
				})
			},
			confirmOrder() {
				if (!this.isLogin) {
					this.$noLog()
					return false
				}
				if (!this.submitflag) {
					this.submitflag = true
					uni.showLoading({
						title: '加载中'
					})
					this.$req.get('/xcx/stationDoor/open', {
						doorId: this.doorId,
						couponsId: ''
					}).then(res => {
						uni.hideLoading()
						this.submitflag = false
						if (res.data.code == 200) {
							uni.showModal({
								title: '洗车开门成功',
								success: () => {
									uni.redirectTo({
										url: '/pages/order/order'
									})
								}
							})
						} else {
							if (res.data.msg == '余额不足请充值') {
								uni.navigateTo({
									url: '/pages/coupon/buyCoupon?doorId=' + this.doorId
								})
							} else {
								uni.showModal({
									title: res.data.msg
								})
							}
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		font-family: PingFang SC;
	}

	.swiper-box {
		height: 500rpx;
		width: 100%;

		image {
			width: 100%;
			height: 500rpx;
		}
	}

	.info-box {
		border-radius: 20rpx 20rpx 0 0;
		background: #fff;
		padding: 20rpx 20rpx;
		margin-top: -20rpx;
		z-index: 2;
	}

	.store-name {
		font-size: 32rpx;
		color: #4F4F4F;
		font-weight: bold;
	}

	.s-zz,
	.s-jm,
	.s-zd,
	.s-qj {
		background: rgba(119, 40, 245, 0.28);
		color: #7728F5;
		font-size: 24rpx;
		width: 90rpx;
		height: 40rpx;
		border-radius: 10rpx;
		margin-left: 20rpx;
	}

	.s-jm {
		background: #1E72CA;
		color: #fff;
	}

	.s-zd {
		background: rgba(64, 149, 229, 0.25);
		color: #4095E5;
	}

	.s-qj {
		background: rgba(15, 64, 245, 0.25);
		color: #0F40F5;
	}

	.jifen-box {
		font-size: 24rpx;
		color: #fff;
		background: #BD3124;
		height: 40rpx;
		border-radius: 10rpx;
		padding: 0 10rpx;
	}

	.s-address {
		font-size: 24rpx;
		color: #6D6A6B;
	}

	.location-icon {
		width: 40rpx;
		height: 40rpx;
	}

	.store-info {
		padding: 20rpx 0;
		border-top: #EFEFEF solid 1px;
		font-size: 24rpx;
		color: #6D6A6B;
	}

	.store-icon {
		width: 28rpx;
		height: 28rpx;
		margin-right: 10rpx;
	}

	.line-box {
		width: 100%;
		height: 20rpx;
		background: #f7f7f7;
	}

	.type-title {
		width: 100%;
		padding: 20rpx 20rpx;
		color: #001629;
		font-size: 28rpx;
	}

	.one-type {
		border: #fff solid 1px;
		box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.1);
		padding: 32rpx 32rpx;
		width: 710rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;

		.type-img {
			width: 100rpx;
			height: 100rpx;
		}

		.type-name {
			font-size: 28rpx;
			font-weight: bold;
			margin-top: 10rpx;
		}

		.type-desc {
			width: calc(100% - 140rpx);
			font-size: 28rpx;
			color: #494a4a;
		}

		.top-box {
			padding-bottom: 20rpx;
			border-bottom: #EFEFEF solid 1px;
		}

		.price-box {
			justify-content: flex-start;
			font-size: 28rpx;
			color: #E99D42;
			margin-top: 20rpx;
		}
	}

	.sel-type {
		border: #17698F solid 1px;
	}

	.room-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: flex-end;

		.one-room {
			margin-top: 40rpx;
			padding: 20rpx 20rpx;
			box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.1);
			border-radius: 10rpx;
			font-size: 28rpx;
			position: relative;
			margin-right: 24rpx;
			z-index: 1;

			image {
				margin-right: 10rpx;
				width: 40rpx;
				height: 40rpx;
			}

			.status-box {
				background: #fff;
				padding: 0 20rpx;
				line-height: 40rpx;
				position: absolute;
				font-size: 24rpx;
				box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.1);
				position: absolute;
				top: -20rpx;
				right: -10rpx;
				border-radius: 100rpx;
				z-index: 22;
			}
		}
	}

	.bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		background: #fff;
		padding: 20rpx 32rpx;
		padding-bottom: 40rpx;
		z-index: 9;
		border-top: #f2f5f5 solid 1px;
		width: 100%;
		justify-content: space-between;
	}

	.account-box,
	.pay-btn {
		font-size: 28rpx;
		color: #1E72CA;
		border: #1E72CA solid 1px;
		border-radius: 10rpx;
		width: 250rpx;
		height: 90rpx;
	}

	.pay-btn {
		width: 400rpx;
		background: #6C6C6C;
		color: #fff;
		border: none;
	}

	.confirm-btn {
		background: #1E72CA;
		color: #fff;
	}
</style>